package top.honlnk.common.utils;

import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import top.honlnk.mapper.ServiceStaffMapper;

@Slf4j
@Component
public class SendMailUtil {

    @Autowired
    private JavaMailSender sender;

    @Autowired
    private ServiceStaffMapper serviceStaffMapper;


    @SuppressWarnings("FieldCanBeLocal")
    private final String from = "honlnk@126.com";


    public void sendMail(String subject, String content, String[] to) {
        MimeMessage mail = sender.createMimeMessage();

        try {
            MimeMessageHelper helper = new MimeMessageHelper(mail, true);
            helper.setSubject(subject);
            helper.setText(content, true);
            helper.setTo(to);
            helper.setFrom(from);
            log.info("简单邮件发送成功");
            sender.send(mail);

        } catch (MessagingException e) {
            log.info("邮件发送失败");
            throw new RuntimeException(e);
        }
    }
}
